package com.hyk.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hyk.domain.AdminAddress;
import com.hyk.dto.R;
import com.hyk.service.AdminAddressService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;

@RestController
@Api(tags = "归集地址控制器")
@RequestMapping("/adminAddress")
public class AdminAddressController {

    @Resource
    private AdminAddressService adminAddressService;

    @GetMapping
    @ApiOperation("根据coinId查询列表")
    public R<Page<AdminAddress>> list(@ApiIgnore Page<AdminAddress> page,String coinId){
        QueryWrapper<AdminAddress> wrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(coinId)){
            wrapper.eq("coin_id",coinId);
        }
        return R.ok(adminAddressService.page(page,wrapper));
    }

    @PostMapping
    @ApiOperation("新增归集地址")
    public R add(@RequestBody AdminAddress adminAddress){
        adminAddressService.saveNew(adminAddress);
        return R.ok();
    }

    @PatchMapping
    @ApiOperation("编辑钱包归集地址")
    public R update(@RequestBody AdminAddress adminAddress){
        boolean update = adminAddressService.updateById(adminAddress);
        if (update) {
            return R.ok();
        }
        return R.fail();
    }

}
